package com.edu.dao;

import com.edu.entity.Role;
import com.edu.entity.Selection;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface RoleMapper {
    //方法一:获取角色的下拉菜单[展示到页面]
    @Select("select r.id value, r.roleName text " +
            "from t_role r")
    List<Selection> getSelections();

    //方法二:设置用户的角色。[设置它的关联项]
    @Insert("insert into t_user_role(userId,roleId)" +
             "values(#{userId},#{roleId})")
    int addRoleAssociation(
            @Param("userId") Integer userId,
            @Param("roleId") Integer roleId
    );

    //方法三:清除用户的角色
    @Delete("delete from t_user_role where userId=#{userId}")
    int removeRoleForUser( @Param("userId") Integer userId);

    //方法四:添加用户的角色
    String FIELDS = "roleName,descript,createDate";
    String VALUES = "#{roleName},#{descript},now()";
    @Insert("INSERT INTO t_role("+ FIELDS +") VALUES("+ VALUES +")")
    @Options(keyProperty="id",keyColumn="id",useGeneratedKeys=true)
    int addRole(Role role);
}
